/*
 * @Author: 张小平
 * @Date:   2025-05-01
 * @Email:  qqshuqian@163.com
 * @Copyright © 2024 aseyun. All rights reserved.
 */
export function customFormulaFun() {
    let customMathList = [];
    customMathList.push({
            name: "加法",
            handler: (a, b) => a + b,
            desc: "加法",
            usage: "加法(a,b)",
            example: "加法(1,2)"
        }, {
            name: "减法",
            handler: (a, b) => a - b,
            desc: "减法",
            usage: "减法(a,b)",
            example: "减法(3,2)"
        }, {
            name: "乘法",
            handler: (a, b) => a * b,
            desc: "乘法",
            usage: "乘法(a,b)",
            example: "乘法(3,2)"
        }
        , {
            name: "除法",
            handler: (a, b) => a / b,
            desc: "除法",
            usage: "除法(a,b)",
            example: "除法(6,2)"
        }, {
            name: "字符串拼接",
            handler: (a, b,c) =>{return "".concat(a,b,c)},
            desc: "字符串拼接",
            usage: "字符串拼接(a,b,c)",
            example: "字符串拼接(a,b,c)"
        },{
            name: "获取当前登录信息",
            handler: (loginInfo,prop) => {return loginInfo[prop]?loginInfo[prop].pvalue:""},
            desc: "获取当前登录信息，loginInfo获取登录人信息 ，登录人ID：userId;登录人姓名:displayName;登录人头像:avatar,性别:sex;手机号:phone;邮箱:email;" +
                "租户主键:tenantId;租户名称:tenantName;角色主键:roleId;角色名称:orgName组织主键:roleId;组织名称:orgName",
            usage: "获取当前登录信息(登录人信息,'displayName')",
            example: "获取当前登录信息(登录人信息,'displayName')"
        },{
            name: "获取URL参数",
            handler: (query,prop) => {return query[prop]},
            desc: "获取当前登录信息登录人ID：id;",
            usage: "获取URL参数(URL参数信息,'id')",
            example: "获取URL参数(URL参数信息,'id')"
        },{
            name: "表单数据字典转化",
            handler: (dics,code,prop) => {  if(dics[code]){return dics[code][prop]}else{ return prop} },
            desc: "表单数据字典转化：性别标识sex;",
            usage: "表单数据字典转化(表单数据字典,'sex','1')",
            example: "表单数据字典转化(表单数据字典,'sex','1')"
        },{
            name: "获取当前时间",
            handler: () => {return new Date()},
            desc: "获取当前时间",
            usage: "获取当前时间",
            example: "获取当前时间"
        }, {
            name: "日期增加天数",
            handler: (days,date) => { if(date==null){date = new Date() }   date.setDate(date.getDate() + days); return date},
            desc: "日期增加天数,没有date 则是当前时间，days可以是负数",
            usage: "日期增加天数",
            example: "日期增加天数(days,date)"
        },{
            name: "日期增加月数",
            handler: (months,date) => { if(date==null){date = new Date() }   date.setMonth(date.getMonth() + months); return date},
            desc: "日期增加月数,没有date 则是当前时间，months可以是负数",
            usage: "日期增加月数",
            example: "日期增加月数(days,date)"
        },
        {
            name: "时间转字符串",
            handler: (fmt,date) => {
                if(!date){
                    date = new Date();
                }
                var o = {
                    "M+" : date.getMonth()+1, //月份
                    "d+" : date.getDate(), //日
                    "h+" : date.getHours()%12 == 0 ? 12 : date.getHours()%12, //小时
                    "H+" : date.getHours(), //小时
                    "m+" : date.getMinutes(), //分
                    "s+" : date.getSeconds(), //秒
                    "q+" : Math.floor((date.getMonth()+3)/3), //季度
                    "S" : date.getMilliseconds() //毫秒
                };
                var week = {
                    "0" : "/u65e5",
                    "1" : "/u4e00",
                    "2" : "/u4e8c",
                    "3" : "/u4e09",
                    "4" : "/u56db",
                    "5" : "/u4e94",
                    "6" : "/u516d"
                };
                if(/(y+)/.test(fmt)){
                    fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
                }
                if(/(E+)/.test(fmt)){
                    fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[date.getDay()+""]);
                }
                for(var k in o){
                    if(new RegExp("("+ k +")").test(fmt)){
                        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
                    }
                }
                return fmt;
            },
            desc: "时间转字符串 yyyy-MM-dd hh:mm:ss.S:2006-07-02 08:09:04.423;" +
                "yyyy-MM-dd EEE hh:mm:ss 2009-03-10 星期二 08:09:04",
            usage: "时间转字符串(格式，时间)",
            example: "时间转字符串('yyyy-MM-dd hh:mm:ss')"
        }
    )

    return customMathList;
}

export function custumVariablesFun() {
    let custumVariablesList = [];
    custumVariablesList.push({
            label: '登录人信息',
            value: '$loginInfo',
            desc: 'JSON对象',
            testdata: {}
        },{
            label: 'URL参数信息',
            value: '$routeQueryInfo',
            desc: 'JSON对象',
            testdata: {}
        },{
            label: '表单数据字典',
            value: '$dic',
            desc: 'JSON对象',
            testdata: {}
        }
    )
    return custumVariablesList;
}

